package com.xbongbong.pro.enums.menu.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.MenuTypeEnum;
import com.xbongbong.pro.enums.AccessLinkEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 资金管理枚举类
 *
 * @author 吴峰
 * @version v1.0
 * @date 2019/1/16 11:25
 * @desrcption 资金管理枚举类
 * @since v1.0
 */
@Getter
public enum FundManagementMenuEnum {

    /**
     * 资金管理枚举类
     */
    PAYMENT_MANAGEMENT("enum.fundManagementMenu.name.payment_management", XbbRefTypeEnum.PAYMENT_MANAGEMENT.getAlias(), XbbRefTypeEnum.PAYMENT_MANAGEMENT.getCode(),
            AccessLinkEnum.PAYMENT_MANAGEMENT,
            "", MenuTypeEnum.GROUP.getType(), XbbRefTypeEnum.CRM.getAlias()),

    /*PAYMENT_TASK("enum.fundManagementMenu.name.payment_task", XbbRefTypeEnum.PAYMENT_TASK.getAlias(), XbbRefTypeEnum.PAYMENT_TASK.getCode(),
            AccessLinkEnum.PAYMENT_TASK, XbbRefTypeEnum.PAYMENT_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),*/

    PAYMENT("enum.fundManagementMenu.name.payment", XbbRefTypeEnum.PAYMENT.getAlias(), XbbRefTypeEnum.PAYMENT.getCode(),
            AccessLinkEnum.PAYMENT,
            XbbRefTypeEnum.PAYMENT_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    PAYMENT_SHEET("enum.fundManagementMenu.name.payment_sheet", XbbRefTypeEnum.PAYMENT_SHEET.getAlias(), XbbRefTypeEnum.PAYMENT_SHEET.getCode(),
            AccessLinkEnum.PAYMENT_SHEET,
            XbbRefTypeEnum.PAYMENT_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    PREPAYMENT_BLANCE("enum.fundManagementMenu.name.prepayment_blance", XbbRefTypeEnum.PREPAYMENT_BALANCE.getAlias(), XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(),
            AccessLinkEnum.PREPAYMENT_BLANCE,
            XbbRefTypeEnum.PAYMENT_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    INVOICE("enum.fundManagementMenu.name.invoice", XbbRefTypeEnum.INVOICE.getAlias(), XbbRefTypeEnum.INVOICE.getCode(),
            AccessLinkEnum.INVOICE, "", MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    STATEMENT("enum.fundManagementMenu.name.statement", XbbRefTypeEnum.STATEMENT.getAlias(), XbbRefTypeEnum.STATEMENT.getCode(),
            AccessLinkEnum.STATEMENT, "", MenuTypeEnum.GROUP.getType(), XbbRefTypeEnum.CRM.getAlias()),

    CUSTOMER_STATEMENT("enum.fundManagementMenu.name.customer_statement", XbbRefTypeEnum.CUSTOMER_STATEMENT.getAlias(), XbbRefTypeEnum.CUSTOMER_STATEMENT.getCode(),
            AccessLinkEnum.CUSTOMER_STATEMENT, XbbRefTypeEnum.STATEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    CUSTOMER_STATEMENT_STATISTIC("enum.fundManagementMenu.name.statement_list", XbbRefTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getAlias(), XbbRefTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getCode(),
            AccessLinkEnum.CUSTOMER_STATEMENT_STATISTIC, XbbRefTypeEnum.STATEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    PAY_MANAGEMENT("enum.fundManagementMenu.name.pay_management", XbbRefTypeEnum.PAY_MANAGEMENT.getAlias(), XbbRefTypeEnum.PAY_MANAGEMENT.getCode(),
            AccessLinkEnum.PAY_MANAGEMENT,
            "", MenuTypeEnum.GROUP.getType(), XbbRefTypeEnum.JXC.getAlias()),

    PAY_PLAN("enum.fundManagementMenu.name.pay_plan", XbbRefTypeEnum.PAY_PLAN.getAlias(), XbbRefTypeEnum.PAY_PLAN.getCode(),
            AccessLinkEnum.PAY_PLAN,
            XbbRefTypeEnum.PAY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.JXC.getAlias()),


    PAY_SHEET("enum.fundManagementMenu.name.pay_sheet", XbbRefTypeEnum.PAY_SHEET.getAlias(), XbbRefTypeEnum.PAY_SHEET.getCode(),
            AccessLinkEnum.PAY_SHEET,
            XbbRefTypeEnum.PAY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.JXC.getAlias()),

    PREPAY_BLANCE("enum.fundManagementMenu.name.prepay_blance", XbbRefTypeEnum.PREPAY_BALANCE.getAlias(), XbbRefTypeEnum.PREPAY_BALANCE.getCode(),
            AccessLinkEnum.PREPAY_BLANCE,
            XbbRefTypeEnum.PAY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.JXC.getAlias()),

    PURCHASE_INVOICE("enum.fundManagementMenu.name.purchase_invoice", XbbRefTypeEnum.PURCHASE_INVOICE.getAlias(), XbbRefTypeEnum.PURCHASE_INVOICE.getCode(),
            AccessLinkEnum.PURCHASE_INVOICE, "", MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.JXC.getAlias()),

    /**
     * 在线支付流水
     */
    ONLINE_PAYMENT_FLOW("enum.fundManagementMenu.name.online_payment_flow", XbbRefTypeEnum.ONLINE_PAYMENT_FLOW.getAlias(), XbbRefTypeEnum.ONLINE_PAYMENT_FLOW.getCode(),
    AccessLinkEnum.ONLINE_PAYMENT_FLOW, "", MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    /**
     * 信用管理
     */
    CREDIT_MANAGEMENT("enum.fundManagementMenu.name.credit_management", XbbRefTypeEnum.CREDIT_MANAGEMENT.getAlias(), XbbRefTypeEnum.CREDIT_MANAGEMENT.getCode(),
            AccessLinkEnum.CREDIT_MANAGEMENT,
            "", MenuTypeEnum.GROUP.getType(), XbbRefTypeEnum.CRM.getAlias()),

    CREDIT_LIMIT("enum.fundManagementMenu.name.credit_limit", XbbRefTypeEnum.CREDIT_LIMIT.getAlias(), XbbRefTypeEnum.CREDIT_LIMIT.getCode(),
            AccessLinkEnum.CREDIT_LIMIT, XbbRefTypeEnum.CREDIT_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    CREDIT_TEMPORARY_LIMIT("enum.fundManagementMenu.name.credit_temporary_limit", XbbRefTypeEnum.CREDIT_TEMPORARY_LIMIT.getAlias(), XbbRefTypeEnum.CREDIT_TEMPORARY_LIMIT.getCode(),
            AccessLinkEnum.CREDIT_TEMPORARY_LIMIT, XbbRefTypeEnum.CREDIT_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    CREDIT_FIXED_LIMIT("enum.fundManagementMenu.name.credit_fixed_limit", XbbRefTypeEnum.CREDIT_FIXED_LIMIT.getAlias(), XbbRefTypeEnum.CREDIT_FIXED_LIMIT.getCode(),
            AccessLinkEnum.CREDIT_FIXED_LIMIT, XbbRefTypeEnum.CREDIT_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    CREDIT_CARD_BILL("enum.fundManagementMenu.name.credit_card_bill", XbbRefTypeEnum.CREDIT_CARD_BILL.getAlias(), XbbRefTypeEnum.CREDIT_CARD_BILL.getCode(),
            AccessLinkEnum.CREDIT_CARD_BILL, XbbRefTypeEnum.CREDIT_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),

    /**
     * 其他收支单枚举类
     */
    OTHER_FUND_MANAGEMENT("enum.fundManagementMenu.name.other_fund_management", XbbRefTypeEnum.OTHER_FUND_MANAGEMENT.getAlias(), XbbRefTypeEnum.OTHER_FUND_MANAGEMENT.getCode(),
            AccessLinkEnum.OTHER_FUND_MANAGEMENT,
            "", MenuTypeEnum.GROUP.getType(), XbbRefTypeEnum.CRM.getAlias()),

    OTHER_INCOME("enum.fundManagementMenu.name.other_income", XbbRefTypeEnum.OTHER_INCOME.getAlias(), XbbRefTypeEnum.OTHER_INCOME.getCode(),
            AccessLinkEnum.OTHER_INCOME,
            XbbRefTypeEnum.OTHER_FUND_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),
    OTHER_EXPENSE("enum.fundManagementMenu.name.other_expense", XbbRefTypeEnum.OTHER_EXPENSE.getAlias(), XbbRefTypeEnum.OTHER_EXPENSE.getCode(),
            AccessLinkEnum.OTHER_EXPENSE,
            XbbRefTypeEnum.OTHER_FUND_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),
    FUND_TRANSFER("enum.fundManagementMenu.name.fund_transfer", XbbRefTypeEnum.FUND_TRANSFER.getAlias(), XbbRefTypeEnum.FUND_TRANSFER.getCode(),
            AccessLinkEnum.FUND_TRANSFER, "", MenuTypeEnum.FORM.getType(), XbbRefTypeEnum.CRM.getAlias()),
    ;

    /**
     * saas应用标示解释
     */
    private String name;
    /**
     * saas应用标示
     *
     * @see XbbRefTypeEnum
     */
    private String alias;
    /**
     * @see XbbRefTypeEnum
     */
    private Integer code;
    /**
     * 对应的链接
     */
    private AccessLinkEnum accessLinkEnum;

    /**
     * 父节点，如果没有父节点，则此值为空字符串
     */
    private String parent;

    /**
     * 类型
     *
     * @see MenuTypeEnum
     */
    private Integer type;

    /**
     * 所属crm或者进销存的业务类型
     * 资金管理中的回款管理和发票管理crm开启才显示，库存管理则随进销存的显示而显示；并且资金管理也可以作为应用参与排序
     */
    private String belongAlias;


    FundManagementMenuEnum(String name, String alias, Integer code, AccessLinkEnum accessLinkEnum, String parent, Integer type, String belongAlias) {
        this.name = name;
        this.alias = alias;
        this.code = code;
        this.accessLinkEnum = accessLinkEnum;
        this.parent = parent;
        this.type = type;
        this.belongAlias = belongAlias;
    }

    public static FundManagementMenuEnum getByAlias(String alias) {
        for (FundManagementMenuEnum fundManagementMenuEnum : values()) {
            if (fundManagementMenuEnum.getAlias().equals(alias)) {
                return fundManagementMenuEnum;
            }
        }
        return null;
    }

    public static FundManagementMenuEnum getByCode(Integer code) {
        for (FundManagementMenuEnum fundManagementMenuEnum : values()) {
            if (fundManagementMenuEnum.getCode().equals(code)) {
                return fundManagementMenuEnum;
            }
        }
        return null;
    }

    /**
     * 需要处理菜单的资金管理枚举list
     * @return java.util.List<com.xbongbong.pro.enums.menu.enums.FundManagementMenuEnum>
     * @author zcp
     * @date 19/11/4 004 14:46
     * @update 19/11/4 004 14:46
     * @since v1.0
     * @version v1.0
     */
    public static List<FundManagementMenuEnum> getAllFund(){
        List<FundManagementMenuEnum> list = new ArrayList<>();
        for (FundManagementMenuEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }
    /**
     * 资金二期菜单处理的枚举list
     * @return java.util.List<com.xbongbong.pro.enums.menu.enums.FundManagementMenuEnum>
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static List<FundManagementMenuEnum> getJxcFund(){
        return Arrays.asList(PAY_MANAGEMENT, PAY_PLAN, PAY_SHEET, PREPAY_BLANCE, PURCHASE_INVOICE);
    }

    /**
     * 要插入的父级菜单枚举集合（只处理父级的：回款管理、付款管理）
     * @return java.util.List<com.xbongbong.pro.enums.menu.enums.FundManagementMenuEnum>
     * @author zcp
     * @date 19/11/4 004 16:15
     * @update 19/11/4 004 16:15
     * @since v1.0
     * @version v1.0
     * @update 2020/2/14 by zcp 改为返回资金二期的父级菜单
     */
    public static List<FundManagementMenuEnum> getParentInsertEnum(){
        return Arrays.asList(PAYMENT_MANAGEMENT);
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    /**
     * 获取有经销商form（及隐藏form）的资金businessType
     * @return java.util.List<java.lang.Integer>
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static List<Integer> getHasDistributorFormBusinessTypes() {
        return Arrays.asList(ONLINE_PAYMENT_FLOW.getCode(), INVOICE.getCode(), PAYMENT.getCode(), PAYMENT_SHEET.getCode(), PREPAYMENT_BLANCE.getCode(), CUSTOMER_STATEMENT.getCode(), CUSTOMER_STATEMENT_STATISTIC.getCode());
    }
    /**
     * 获取有经销商form（及隐藏form）的资金businessType alias
     * @return java.util.List<java.lang.Integer>
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static List<String> getHasDistributorFormBusinessAlias() {
        return Arrays.asList(ONLINE_PAYMENT_FLOW.getAlias(), INVOICE.getAlias(), PAYMENT.getAlias(), PAYMENT_SHEET.getAlias(), PREPAYMENT_BLANCE.getAlias(), CUSTOMER_STATEMENT.getAlias(), CUSTOMER_STATEMENT_STATISTIC.getAlias());
    }
}
